package com.winhc.net.web;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.winhc.net.dao.ContentDao;
import com.winhc.net.db.mybatis.dataobject.WebsiteContent;
import com.winhc.net.dto.QueryContentRequest;
import com.winhc.net.dto.RequestDTO;
import com.winhc.net.dto.ResponseDTO;

/**
 * 描述: 内容管理rest风格Controller
 */
@RestController
@RequestMapping(value = "content")
public class ContentController {

	@Resource
	ContentDao contentDao;

	/**
	 * 查询
	 */
	@RequestMapping(method = RequestMethod.GET)
	public ResponseDTO get(RequestDTO header, QueryContentRequest queryContentRequest) {
		return contentDao.queryContent(header, queryContentRequest);
	}

	/**
	 * 增加
	 */
	@RequestMapping(method = RequestMethod.POST)
	public String add(@RequestBody WebsiteContent websiteContent) {
		
		int x = contentDao.saveContent(websiteContent);
		if(x > 0) {
			return "success";
		}else {
			return "fail";
		}
	}

	/**
	 * 更新
	 */
	@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
	public String update(@PathVariable long id, WebsiteContent websiteContent) {
		
		int x = contentDao.updateContent(websiteContent);
		if(x > 0) {
			return "success";
		}else {
			return "fail";
		}
	}

	/**
	 * 删除
	 */
	@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
	public String delete(@PathVariable long id) {
		
		int x = contentDao.delContent(id);
		if(x > 0) {
			return "success";
		}else {
			return "fail";
		}
	}

	
}